package com.elai.web.controller.baseconfig;

import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.baseconfig.domain.ChannelDO;
import com.elai.baseconfig.service.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 触达通道Controller
 *
 * @author elai
 * @date 2021-04-03
 */
@RestController
@RequestMapping("/config/channel")
public class ChannelController extends BaseController
{
    @Autowired
    private ChannelService channelService;

    /**
     * 查询触达通道列表
     */
    @PreAuthorize("@ss.hasPermi('config:channel:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelDO channel)
    {
        startPage();
        List<ChannelDO> list = channelService.selectChannelList(channel);
        return getDataTable(list);
    }


    @GetMapping("/channelData")
    public AjaxResult channelData(ChannelDO channel)
    {
        channel.setStatus("Y");
        List<ChannelDO> list = channelService.selectChannelList(channel);
        return AjaxResult.success(list);
    }

    /**
     * 导出触达通道列表
     */
    @PreAuthorize("@ss.hasPermi('config:channel:export')")
    @Log(title = "触达通道", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChannelDO channel)
    {
        List<ChannelDO> list = channelService.selectChannelList(channel);
        ExcelUtil<ChannelDO> util = new ExcelUtil<ChannelDO>(ChannelDO.class);
        return util.exportExcel(list, "channel");
    }

    /**
     * 获取触达通道详细信息
     */
    @PreAuthorize("@ss.hasPermi('config:channel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(channelService.selectChannelById(id));
    }

    /**
     * 新增触达通道
     */
    @PreAuthorize("@ss.hasPermi('config:channel:add')")
    @Log(title = "触达通道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelDO channel)
    {
        return toAjax(channelService.insertChannel(channel));
    }

    /**
     * 修改触达通道
     */
    @PreAuthorize("@ss.hasPermi('config:channel:edit')")
    @Log(title = "触达通道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChannelDO channel)
    {
        return toAjax(channelService.updateChannel(channel));
    }

    /**
     * 删除触达通道
     */
    @PreAuthorize("@ss.hasPermi('config:channel:remove')")
    @Log(title = "触达通道", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(channelService.deleteChannelByIds(ids));
    }
}
